/**
 * 作者: hxl
 * 日期: 2025-05-14 10:16:09
 * 备注: 用户每日签到数据
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserDailySign;
import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class UserDailySignModel extends BaseModel implements Model {
    public static final String LISTKEY = "";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 用户id
    protected int type; // 分组类型
    protected int day; // 第几天
    protected byte isCharge; // 今日是否充值
    protected byte isReward; // 今日是否领奖
    protected byte isChargeReward; // 今日是否领充值奖励
    protected long resetTime; // 重置时间
    protected byte isWatchAd; // 是否看过广告
    protected byte isAdReward; // 今日是否领取广告奖励

    public void reset() {
    }

    protected String getKey() {
        return "UserDailySign." + id;
    }

    protected String getListKey() {
        return null;
    }

    protected String getListItemKey() {
        return null;
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("user_daily_sign"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, id, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, id, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 用户id
        obj.put("type", type); // 分组类型
        obj.put("day", day); // 第几天
        obj.put("isCharge", isCharge); // 今日是否充值
        obj.put("isReward", isReward); // 今日是否领奖
        obj.put("isChargeReward", isChargeReward); // 今日是否领充值奖励
        obj.put("resetTime", resetTime); // 重置时间
        obj.put("isWatchAd", isWatchAd); // 是否看过广告
        obj.put("isAdReward", isAdReward); // 今日是否领取广告奖励
        return obj;
    }

    public PBUserDailySign.Builder takeInitBuilder() {
        PBUserDailySign.Builder sb = PBUserDailySign.newBuilder();
        if (type != 0) {
            sb.setType(type);
        }
        if (day != 0) {
            sb.setDay(day);
        }
        return sb;
    }

    public PBUserDailySign.Builder takeBuilder() {
        if (updateObj == null || updateObj.isEmpty()) {
            return takeInitBuilder();
        }
        PBUserDailySign.Builder sb = PBUserDailySign.newBuilder();
        if (isFieldUpdate("type")) {
            sb.setType(type);
        }
        if (isFieldUpdate("day")) {
            sb.setDay(day);
        }
        return sb;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public int getType() {
        return type;
    }

    public void putType(int type) {
        if (this.type != type) {
            this.type = type;
            updateRedisHashField(getKey(), "type", this.type);
        }
    }

    public void addType(int value) {
        this.type += value;
        updateRedisHashField(getKey(), "type", this.type);
    }

    public int getDay() {
        return day;
    }

    public void putDay(int day) {
        if (this.day != day) {
            this.day = day;
            updateRedisHashField(getKey(), "day", this.day);
        }
    }

    public void addDay(int value) {
        this.day += value;
        updateRedisHashField(getKey(), "day", this.day);
    }

    public byte getIsCharge() {
        return isCharge;
    }

    public void putIsCharge(byte isCharge) {
        if (this.isCharge != isCharge) {
            this.isCharge = isCharge;
            updateRedisHashField(getKey(), "isCharge", this.isCharge);
        }
    }

    public void addIsCharge(byte value) {
        this.isCharge += value;
        updateRedisHashField(getKey(), "isCharge", this.isCharge);
    }

    public byte getIsReward() {
        return isReward;
    }

    public void putIsReward(byte isReward) {
        if (this.isReward != isReward) {
            this.isReward = isReward;
            updateRedisHashField(getKey(), "isReward", this.isReward);
        }
    }

    public void addIsReward(byte value) {
        this.isReward += value;
        updateRedisHashField(getKey(), "isReward", this.isReward);
    }

    public byte getIsChargeReward() {
        return isChargeReward;
    }

    public void putIsChargeReward(byte isChargeReward) {
        if (this.isChargeReward != isChargeReward) {
            this.isChargeReward = isChargeReward;
            updateRedisHashField(getKey(), "isChargeReward", this.isChargeReward);
        }
    }

    public void addIsChargeReward(byte value) {
        this.isChargeReward += value;
        updateRedisHashField(getKey(), "isChargeReward", this.isChargeReward);
    }

    public long getResetTime() {
        return resetTime;
    }

    public void putResetTime(long resetTime) {
        if (this.resetTime != resetTime) {
            this.resetTime = resetTime;
            updateRedisHashField(getKey(), "resetTime", this.resetTime);
        }
    }

    public void addResetTime(long value) {
        this.resetTime += value;
        updateRedisHashField(getKey(), "resetTime", this.resetTime);
    }

    public byte getIsWatchAd() {
        return isWatchAd;
    }

    public void putIsWatchAd(byte isWatchAd) {
        if (this.isWatchAd != isWatchAd) {
            this.isWatchAd = isWatchAd;
            updateRedisHashField(getKey(), "isWatchAd", this.isWatchAd);
        }
    }

    public void addIsWatchAd(byte value) {
        this.isWatchAd += value;
        updateRedisHashField(getKey(), "isWatchAd", this.isWatchAd);
    }

    public byte getIsAdReward() {
        return isAdReward;
    }

    public void putIsAdReward(byte isAdReward) {
        if (this.isAdReward != isAdReward) {
            this.isAdReward = isAdReward;
            updateRedisHashField(getKey(), "isAdReward", this.isAdReward);
        }
    }

    public void addIsAdReward(byte value) {
        this.isAdReward += value;
        updateRedisHashField(getKey(), "isAdReward", this.isAdReward);
    }

}